home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-10-12 | 2.8 KB | 99 lines | [TEXT/CWIE] |
- unit WEDebug;
-
- { WASTE PROJECT }
- { Debugging Routines }
-
- { Copyright © 1993-1994 Marco Piovanelli }
- { All Rights Reserved }
-
- interface
- uses
- WEInterface;
-
- {$IFC WASTE_DEBUG}
- procedure _WEAssert (condition: Boolean;
- message: string);
- procedure _WESanityCheck (hWE: WEHandle);
- {$ENDC}
-
- implementation
-
- {$IFC WASTE_DEBUG}
-
- procedure _WEAssert (condition: Boolean;
- message: string);
- begin
- if (condition = false) then
- begin
- message := Concat('Assertion Failed: ', message);
- DebugStr(message);
- end;
- end; { _WEAssert }
-
- procedure _WESanityCheck (hWE: WEHandle);
-
- { _WESanityCheck performs several checks on two key data structures: }
- { the run array and the style table, verifying a number of assertions. }
- { This routine made it possible to identify many subtle bugs during development. }
-
- var
- pWE: WEPtr;
- pRuns: RunArrayPtr;
- pStyles: StyleTablePtr;
- i, j, refCount: LongInt;
- begin
-
- { we aren't going to move memory }
- pWE := hWE^;
- pRuns := pWE^.hRuns^;
- pStyles := pWE^.hStyles^;
-
- { check the consistency of the run array }
- { first runStart must be zero }
- _WEAssert(pRuns^[0].runStart = 0, 'First run array element is bad');
-
- { last (dummy) runStart must be textLength + 1 and styleIndex must be -1 }
- _WEAssert((pRuns^[pWE^.nRuns].runStart = pWE^.textLength + 1) and (pRuns^[pWE^.nRuns].styleIndex = -1), 'Last run array element is bad');
-
- { all runs must be at least one character long }
- for i := pWE^.nRuns - 1 downto 0 do
- _WEAssert(pRuns^[i + 1].runStart - pRuns^[i].runStart > 0, 'Run length less than one');
-
- { no two consecutive runs may reference the same style }
- for i := pWE^.nRuns - 1 downto 0 do
- _WEAssert(pRuns^[i + 1].styleIndex <> pRuns^[i].styleIndex, 'Spurious run boundary');
-
- { all run array elements (except the last dummy entry) must reference an existing style }
- j := pWE^.nStyles;
- for i := pWE^.nRuns - 1 downto 0 do
- _WEAssert((pRuns^[i].styleIndex >= 0) and (pRuns^[i].styleIndex < j), 'Invalid style index');
-
- { the number of runs referencing each style in the style table }
- { must match the style reference count }
- for j := pWE^.nStyles - 1 downto 0 do
- begin
- refCount := 0;
- for i := pWE^.nRuns - 1 downto 0 do
- if (pRuns^[i].styleIndex = j) then
- refCount := refCount + 1;
- _WEAssert(pStyles^[j].refCount = refCount, 'Bad style reference count');
- end;
-
- { there may not be two identical entries in the style table (except for unused entries) }
- for i := pWE^.nStyles - 1 downto 1 do
- begin
- if (pStyles^[i].refCount = 0) then
- Cycle;
- for j := i - 1 downto 0 do
- begin
- if (pStyles^[j].refCount = 0) then
- Cycle;
- _WEAssert(_WEBlockCmp(@pStyles^[i].info, @pStyles^[j].info, SizeOf(pStyles^[i].info)) = false, 'Duplicate entry in style table');
- end;
- end;
-
- end; { _WESanityCheck }
-
- {$ENDC}
-
- end.